package org.NooLab.itexx.utilities;

import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;


/*
 * usage:
 * 
 * htmlPane.setEditable(false); 
 * htmlPane.addHyperlinkListener(new HyperActive());

 */

public class HyperActive implements HyperlinkListener {

    public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        	
            JEditorPane pane = (JEditorPane) e.getSource();
            
            if (e instanceof HTMLFrameHyperlinkEvent) {
            
            	HTMLFrameHyperlinkEvent  evt = (HTMLFrameHyperlinkEvent)e;
                HTMLDocument doc = (HTMLDocument)pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
                
            } else {
                
            	try {
                    pane.setPage(e.getURL());
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
        }
    }
}